import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.webapp.WebAppContext;

public class JettyServer_start {

	public static void main(String[] args) throws Exception {
		long start = System.currentTimeMillis();
		Server jettyServer = null;
		try {
			jettyServer = new Server();

			SelectChannelConnector conn = new SelectChannelConnector();
			conn.setHost(args != null && args.length > 0 ? args[0] : "0.0.0.0");
			conn.setPort(args != null && args.length > 1 ? Integer.parseInt(args[1]) : 5007);
			jettyServer.setConnectors(new Connector[] { conn });

			WebAppContext context = new WebAppContext();
			context.setContextPath("/");
			context.setWar("src/main/webapp");
			context.setDefaultsDescriptor("./src/test/resources/webdefault.xml");
			jettyServer.setStopAtShutdown(true);
			jettyServer.setHandler(context);
			jettyServer.start();
			// jettyServer.join();

		} catch (Exception ignore) {
			if (jettyServer != null) {
				try {
					jettyServer.stop();
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		}

		System.out.println("Jetty started in " + (System.currentTimeMillis() - start) + " ms.");
	}
}
